package com.example.demo.asm2;


import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassWriter;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {

    public static void main(String[] args) throws IOException {
        // 读取原始类的字节码
        FileInputStream fis = new FileInputStream("path/to/your/InputClass.class");
        ClassReader classReader = new ClassReader(fis);

        // 创建一个 ClassWriter 对象，用于生成修改后的字节码
        ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);

        // 使用自定义的 ClassVisitor 处理字节码
        CustomClassVisitor customClassVisitor = new CustomClassVisitor(classWriter);
        classReader.accept(customClassVisitor, 0);

        // 将修改后的字节码写入文件
        byte[] modifiedBytecode = classWriter.toByteArray();
        FileOutputStream fos = new FileOutputStream("path/to/your/OutputClass.class");
        fos.write(modifiedBytecode);
        fos.close();
    }
}
